#include "lan2cal.h"

#include <QPainter>
#include <QDebug>
#include <QTableView>
#include <QHeaderView>
#include <QTextCharFormat>
LAN2STA
Lan2Cal::Lan2Cal(QWidget *parent, int width, int height)
{
    this->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
    this->setNavigationBarVisible(false);
    QTableView* mview=this->findChild<QTableView*>("qt_calendar_calendarview");

    mview->horizontalHeader()->setStyleSheet(QString("QHeaderView::section{background:%1;}").arg(ms_bgcolor));

    mview->setStyleSheet(QString("QTableView{background:%1}").arg(ms_bgcolor));
    //    QTextCharFormat weekf;
    //    weekf.setForeground(QBrush(QColor("#ffff00"),Qt::SolidPattern));
    //    this->setWeekdayTextFormat(Qt::Saturday,weekf);

    QTextCharFormat ff;
    ff.setBackground(QBrush(QColor(ms_bgcolor),Qt::SolidPattern));
    this->setHeaderTextFormat(ff);

    this->setFixedSize(width,height);
//    m_size=(width-10)/7;

}

void Lan2Cal::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
{
    if(date==selectedDate()){

        painter->save();
        painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
        painter->setPen(QPen(QColor(ms_selectedcolor),1));
        painter->setBrush(QBrush(QColor(ms_selectedcolor),Qt::SolidPattern));
        QRect mrect(rect.x(),rect.y(),rect.width(),rect.height());
        int  m_size=rect.width()/2-9;
        painter->drawEllipse(QPointF(mrect.x()+mrect.width()/2,mrect.y()+mrect.height()/2),m_size,m_size);
        //        painter->drawRect(mrect);

        painter->setPen(QPen(QColor(ms_bgcolor),1));

        painter->drawText(mrect,Qt::AlignCenter,QString::asprintf("%d",date.day()));
        //        painter->fillRect(rect,QGradient::NoGradient);
        //        painter->setPen(QPen(QColor("#000000"),1));
        //qDebug()<<"selcted";
        painter->restore();
    }else{
        QCalendarWidget::paintCell(painter,rect,date);
    }
}
LAN2END
